/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef ENVELOPE_H
#define ENVELOPE_H

#include <vector>

struct EnvelopePoint
{
	int position;
	int value;

	EnvelopePoint( int position, int value )
	:	position( position ),
		value( value )
	{}
};

class EnvelopePoints : public std::vector< EnvelopePoint >
{};

/*Representation class for running envelope*/
class Envelope
{
	friend class EnvelopeBuilder;

	int sustain_point;
	int loop_begin;
	int loop_end;

	bool active;
	bool sustain_active;
	bool loop_active;

	EnvelopePoints envelope_points;
public:
	Envelope();

	bool is_active()const;
	bool is_sustain_active()const;
	bool is_loop_active()const;
	int get_sustain_position()const;
	int get_point_position( int point_number )const;
	int get_loop_end_point()const;
	int get_loop_start_point()const;
	int size()const;
	int get_point_value( int point_number )const;
};

inline int Envelope::size()const
{
	return envelope_points.size();
}
inline int Envelope::get_point_value( int point_number )const
{
	if( point_number < 0 || point_number >= size() )
		return 0;

	return envelope_points[point_number].value;
}
inline int Envelope::get_loop_start_point()const
{
	return loop_begin;
}
inline int Envelope::get_loop_end_point()const
{
	return loop_end;
}
inline int Envelope::get_point_position( int point_number )const
{
	if( point_number < 0 || point_number >= size() )
		return 0;

	return envelope_points[point_number].position;
}
inline int Envelope::get_sustain_position()const
{
	return envelope_points[sustain_point].position;
}
inline bool Envelope::is_loop_active()const
{
	return loop_active;
}
inline bool Envelope::is_sustain_active()const
{
	return sustain_active;
}
inline bool Envelope::is_active()const
{
	return active;
}
inline Envelope::Envelope()
:	sustain_point( 0 ),
	loop_begin( 0 ),
	loop_end( 0 ),
	active ( false ),
	sustain_active( false ),
	loop_active( false )
{}

#endif